package cn.lzj.service.business.Impl;

import cn.lzj.mapper.ProductMapper;
import cn.lzj.mapper.UserMapper;
import cn.lzj.pojo.*;
import cn.lzj.service.business.BusinessService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import cn.lzj.mapper.productGeneratorMapper;

import java.util.List;

@Service
public class BusinessServiceImpl implements BusinessService {

    @Resource
    private UserMapper userMapper;

    @Resource
    private ProductMapper productMapper;

    @Resource
    private productGeneratorMapper productGeneratorMapper;

    @Override
    public User selectUserById(Integer id) {
        return userMapper.getUserById(id);
    }

    @Override
    public boolean addProduct(productGenerator product) {
        int insert = productGeneratorMapper.insert(product);
        return insert==1;
    }

    @Override
    public boolean delProduct(productGenerator product) {
        productGeneratorExample example = new productGeneratorExample();
        example.createCriteria()
                .andProductidEqualTo(product.getProductid());
        int count = productGeneratorMapper.deleteByExample(example);
        return count==1;
    }

    @Override
    public boolean updateProduct(productGenerator product) {
        int count = productGeneratorMapper.updateByPrimaryKey(product);
        return count == 1;
    }

    @Override
    public List<productGenerator> selectProductByUserid(User user) {
        productGeneratorExample example = new productGeneratorExample();
        example.createCriteria()
                .andUseridEqualTo(user.userId);
        List<productGenerator> productGeneratorList = productGeneratorMapper.selectByExample(example);

        return productGeneratorList;
    }


    public productGenerator selectProductGeneratorById(Integer proId){
        productGeneratorExample example = new productGeneratorExample();
        example.createCriteria()
                .andProductidEqualTo(proId);

        List<productGenerator> productGeneratorList = productGeneratorMapper.selectByExample(example);
        return productGeneratorList.get(0);
    }
}
